home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / inetray / utils.c < prev    next >
C/C++ Source or Header  |  1993-08-15  |  2KB  |  79 lines

  1. /*======================================================================
  2.                     U T I L S . C 
  3.                     doc: Mon Mar 23 11:42:27 1992
  4.                     dlm: Fri Jul 23 16:05:28 1993
  5.                     (c) 1992 ant@ips.id.ethz.ch
  6.                     uE-Info: 19 0 T 0 0 72 2 2 8 ofnI
  7. ======================================================================*/
  8.  
  9. #include    <stdio.h>
  10. #include    <pwd.h>
  11. #include    <string.h>
  12. #include    <sys/types.h>
  13. #include    <sys/param.h>
  14. #include    <rpc/rpc.h>
  15. #include    "inetray.h"
  16. #include    "config.h"
  17. #include    "common.h"
  18.  
  19. void VersionPrint() {}            /* the raylibs need that */
  20.     
  21. void stripHome(uid,path)        /* home -> ~ */
  22. uid_t uid; char *path;
  23. {
  24.     int    i = 0,t = 0;
  25.     char    cwd[MAXPATHLEN],home[MAXPATHLEN];
  26.     struct passwd *p;
  27.  
  28.     if (path[0] != '/')        /* errmes from getwd */
  29.         return;
  30.     getcwd(cwd,MAXPATHLEN);        /* save current wdir */
  31.     p = getpwuid(geteuid());    /* get real home dir */
  32.     if (p == NULL) return;
  33.     if (chdir(p->pw_dir) < 0)    /* can't access home */ 
  34.         strncpy(home,cwd,MAXPATHLEN);
  35.     else                 /* real name of home */
  36.         getcwd(home,MAXPATHLEN);/* automount ... */
  37.     if (chdir(cwd) < 0)         /* shouldn't happen at all! */
  38.         getcwd(path,MAXPATHLEN);
  39.  
  40.     while ((home[i] != '\0') &&    /* strip out home */
  41.            (path[i] == home[i])) i++;
  42.     if (home[i] != '\0') return;
  43.  
  44.     path[t++] = '~';        /* add tilde */
  45.     while ((path[t++] = path[i++]) != '\0') ; /* copy rest */
  46. }
  47.  
  48. void stripHead(head,path)        /* for AutoMount ... */
  49. char *path,*head;
  50. {
  51.     int    t = 0, s = 0;
  52.  
  53.     while ((head[s] != '\0') &&
  54.                (path[s] != '\0') &&
  55.            (path[s] == head[s])) s++;
  56.     if ((s == 0) || (head[s] != '\0')) return;
  57.     while ((path[t++] = path[s++]) != '\0') ;
  58.     if (chdir(path) < 0) getcwd(path,MAXPATHLEN);
  59. }
  60.  
  61. void addHome(uid,pIn,pOut)        /* ~ -> home */
  62. uid_t uid; char *pIn,*pOut;
  63. {
  64.     int    s = 0,t = 0,i = 0;
  65.     struct passwd *p;
  66.  
  67.     if (pIn[s] == '~') {        /* do subst */
  68.         s++;
  69.         p = getpwuid(geteuid());
  70.         if (p == NULL) 
  71.             pOut[t++] = '.';
  72.         else
  73.             while (p->pw_dir[i] != '\0')
  74.                 pOut[t++] = p->pw_dir[i++];
  75.     }
  76.     while ((pOut[t++] = pIn[s++]) != '\0') ;
  77. }
  78.         
  79.